
// MAIN

// standard global variables
var container, scene, camera, renderer, controls, stats;
var clock = new THREE.Clock();
// custom global variables
var cube;

// init();
// animate();

// FUNCTIONS 		
function cube_init() 
{
	// SCENE
	scene = new THREE.Scene();
	// CAMERA
	var SCREEN_WIDTH = 250, SCREEN_HEIGHT = 250;
	var VIEW_ANGLE = 45, ASPECT = SCREEN_WIDTH / SCREEN_HEIGHT, NEAR = 0.1, FAR = 20000;
	camera = new THREE.PerspectiveCamera( VIEW_ANGLE, ASPECT, NEAR, FAR);
	scene.add(camera);
	camera.position.set(0,70,250);
	camera.lookAt(scene.position);	
	// RENDERER
	if ( Detector.webgl )
		renderer = new THREE.WebGLRenderer( {antialias:true} );
	else
		renderer = new THREE.CanvasRenderer(); 
	renderer.setSize(SCREEN_WIDTH, SCREEN_HEIGHT);
    
    container = document.getElementsByClassName('cube')[0];
	container.appendChild( renderer.domElement );

	// CONTROLS
	controls = new THREE.OrbitControls( camera, renderer.domElement );
            
    hemiLight = new THREE.HemisphereLight( 0xffffff, 0xffffff, 0.6 );
    hemiLight.color.setHSL( 0.6, 1, 0.6 );
    hemiLight.groundColor.setHSL( 0.095, 1, 0.75 );
    hemiLight.position.set( 0, 100, 0 );
    scene.add( hemiLight );
                
    dirLight = new THREE.DirectionalLight( 0xffffff, 1 );
    dirLight.color.setHSL( 0.1, 1, 0.95 );
    dirLight.position.set( -1, 1.75, 1 );
    dirLight.position.multiplyScalar( 50 );
    scene.add( dirLight );

    dirLight.castShadow = true;
    dirLight.shadowMapWidth = 2048;
    dirLight.shadowMapHeight = 2048;
    
	////////////
	// CUSTOM //
	////////////

    var met1 = new THREE.MeshPhongMaterial( { color: 0xff0000, shininess: 20, vertexColors: THREE.FaceColors, shading: THREE.FlatShading } );
	var multiMaterial = [ met1 ]; 

	// cube
	var shape = THREE.SceneUtils.createMultiMaterialObject( 
		new THREE.CubeGeometry(110, 110, 110, 2, 2, 2), 
		multiMaterial );
	shape.position.set(0, 0, 0);
	scene.add( shape );
}

function cube_animate() 
{
    requestAnimationFrame(cube_animate);
	render();		
	update();
}

function update()
{	
	controls.update();
}
function render() 
{
	renderer.render( scene, camera );
}
